package com.moto.mapper;

import com.github.pagehelper.Page;
import com.moto.entity.Emp;
import com.moto.entity.User;
import com.moto.entityDto.PageDto;
import com.moto.entityDto.UserPageDto;
import com.moto.entityDto.UserUpdateDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 员工表 Mapper 接口
 * </p>
 *
 * @author afei
 * @since 2023-08-28
 */
@Mapper
public interface EmpMapper{
    @Select("select * from emp where username = #{username}")
    Emp getByUsername(String username);

    /**
     * 新增员工
     * @param emp
     */
    @Insert("insert into emp (username,password,photo,sex,age,permission,is_delete) values " +
            "(#{username},#{password},#{photo},#{sex},#{age},#{permission},#{isDelete})")
    void add(Emp emp);

    /**
     * 查询所有员工信息
     *
     * @return
     */
    Page<Emp> findAllEmp(PageDto pageDto);

    @Update("update emp set is_delete=0 where id = #{id}")
    void deleteEmpById(int id);

    @Select("select username,photo,sex,age from emp where id=#{id}")
    Emp findEmpByID(int id);

    void updateEmpById(Emp emp);

    /**
     * 员工删除用户
     */
    @Update("update user set is_delete=0 where id = #{id}")
    void deleteUserById(int id);

    /**
     * 员工修改用户
     */
    void updateUser(UserUpdateDto userUpdateDto);

    @Select("select * from user where id=#{id}")
    User findUserById(int id);

    /**
     * 员工模糊查询查询所有用户信息
     */
    Page<User> findLikeUser(UserPageDto userPageDto);



}
